<template>
    <div class="header">
        <div class="logo">放心选运营系统</div>
        <div class="user-info">
            <el-dropdown trigger="click" @command="handleCommand">
                <span class="el-dropdown-link">
                    <!--<img class="user-logo" src="../../../static/img/img.jpg">-->
                    &nbsp;{{username}}
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="loginout">退出</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </div>
    </div>
</template>
<script>
    import Api from '~util/api.js';
    import Cookie from '~util/js.cookie.js'
    export default {
        data() {
            return {
                username: '123'
            }
        },
        created(){
            // let user = Cookie.get('sso-user');
            // this.setUsername(user);
            // !user && (async () => {
            //     let res = await this.$_http(Api.loginSSO, 'jsonp', {redirect: window.location.href})
            //     if (res.redirect) {
            //         alert(res.redirect)
            //         window.location.href = res.redirect;
            //     } else {
            //         this.setUsername(user);
            //     }
            // })()
        },
        computed: {},
        methods: {
            setUsername(user){
                user = user || Cookie.get('sso-user');
                if (user) {
                    user = JSON.parse(JSON.parse(user));
                    this.username = user.username;
                }
            },
            handleCommand(command) {
                if (command == 'loginout') {
                    Cookie.remove('sso-user');
                    window.location.href = Api.logoutSSO + '?redirect=https://sso.vdian.net/sso/login?redirect=' + window.location.href;
                }
            }
        }
    }
</script>
<style scoped>
    .header {
        position: relative;
        box-sizing: border-box;
        width: 100%;
        height: 70px;
        font-size: 22px;
        line-height: 70px;
        color: #FFF;
    }

    .header .logo {
        float: left;
        width: 250px;
        text-align: center;
    }

    .user-info {
        float: right;
        padding-right: 50px;
        font-size: 16px;
        color: #FFF;
    }

    .user-info .el-dropdown-link {
        position: relative;
        display: inline-block;
        padding-left: 50px;
        color: #FFF;
        cursor: pointer;
        vertical-align: middle;
    }

    .user-info .user-logo {
        position: absolute;
        left: 0;
        top: 15px;
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }

    .el-dropdown-menu__item {
        text-align: center;
    }
</style>
